-- Test modulo operator for fixeddecimal type
-- modulo operator between MONEY/SMALLMONEY and MONEY/SMALLMONEY
-- SMALLMONEY is between -214748.3648 to 214748.3647
-- MONEY is between -922337203685477.5808 to 922337203685477.5807
SELECT CAST(-15.5 AS MONEY) % CAST(24.0 AS MONEY);
GO
SELECT CAST(-273434.2737 AS MONEY) % CAST(283.2245 AS MONEY);
GO
SELECT CAST(-27328391434.2737 AS MONEY) % CAST(283828323.2273 AS MONEY);
GO
SELECT CAST(-27328391434.2737 AS MONEY) % CAST(-283828323.2273 AS MONEY);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(283.2245 AS MONEY);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(-922337203685477.5808 AS MONEY);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(1 AS MONEY);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(0.0001 AS MONEY);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(-283828323.2273 AS MONEY);
GO
SELECT CAST(-922337203685477.5808 AS MONEY) % CAST(922337203685477.5807 AS MONEY);
GO
SELECT CAST(-922337203685477.5808 AS MONEY) % CAST(283.2245 AS MONEY);
GO
SELECT CAST(-922337203685477.5808 AS MONEY) % CAST(1 AS MONEY);
GO
SELECT CAST(-922337203685477.5808 AS MONEY) % CAST(0.0001 AS MONEY);
GO
SELECT CAST(-922337203685477.5808 AS MONEY) % CAST(-283828323.2273 AS MONEY);
GO
SELECT CAST(0.00 AS MONEY) % CAST(-922337203685477.5808 AS MONEY);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(0.00 AS MONEY);
GO

SELECT CAST(-214748.3648 AS SMALLMONEY) % CAST(283.2245 AS SMALLMONEY);
GO
SELECT CAST(214748.3647 AS SMALLMONEY) % CAST(283.2245 AS SMALLMONEY);
GO
SELECT CAST(214748.3647 AS SMALLMONEY) % CAST(0.0001 AS SMALLMONEY);
GO
SELECT CAST(-214748.3648 AS SMALLMONEY) % CAST(0.0001 AS SMALLMONEY);
GO

SELECT CAST(-922337203685477.5808 AS MONEY) % CAST(-214748.3648 AS SMALLMONEY);
GO
SELECT CAST(5477.5808 AS MONEY) % CAST(-214748.3648 AS SMALLMONEY);
GO
SELECT CAST(-214748.3648 AS SMALLMONEY) % CAST(5477.5808 AS MONEY);
GO

-- modulo operator between MONEY/SMALLMONEY and Integer
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(2833 AS SMALLINT);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(228325833 AS INT);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(293228325827 AS BIGINT);
GO
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(7 AS TINYINT);
GO
SELECT CAST(2833 AS SMALLINT) % CAST(283.2128 AS SMALLMONEY);
GO
SELECT CAST(125833 AS INT) % CAST(-28322.8217 AS SMALLMONEY);
GO
SELECT CAST(-20827 AS BIGINT) % CAST(-98272.1123 AS SMALLMONEY);
GO
SELECT CAST(228325833 AS INT) % CAST(-28322.8217 AS SMALLMONEY);
GO
SELECT CAST(293228325827 AS BIGINT) % CAST(-98272.1123 AS SMALLMONEY);
GO
SELECT CAST(-98272.1123 AS SMALLMONEY) % CAST(7 AS TINYINT);
GO

-- modulo operator between MONEY/SMALLMONEY and DECIMAL
-- use the postgres internal numeric_mod
SELECT CAST(922337203685477.5807 AS MONEY) % CAST(2833.292334 AS NUMERIC(12, 7));
GO
SELECT CAST(289383292919292.238382 AS NUMERIC(30, 5)) % CAST(-922337203685477.5808 AS MONEY);
GO
SELECT CAST(-98272.1123 AS SMALLMONEY) % CAST(7.2 AS NUMERIC(5, 4));
GO
SELECT CAST(289383292919292.238382 AS NUMERIC(30, 5)) % CAST(-98272.1123 AS SMALLMONEY);
GO

SELECT a, a % 1 AS MOD_INT, a % CAST(1 AS MONEY) AS MOD_MONEY, a % CAST(1 AS DECIMAL(10, 5)) AS MOD_DECIMAL FROM fixeddecimal_modulo_t1;
GO
